package com.template.templateuser.domain.web;

import com.template.templatecommon.domain.Result;
import com.template.templateuser.domain.dto.SysUserDTO;
import com.template.templateuser.domain.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/sys-user")
@Api(tags = "用户Api")
public class SysUserController {

    @Autowired
   private  SysUserService sysUserService;

    /**
     * 得到用户列表
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("得到用户列表")
    public List<SysUserDTO> getSysUserList(HttpServletResponse response)throws Exception{
        return sysUserService.getSysUserList();
    }

    /**
     * 创建用户
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("创建用户")
    public int saveUser(@RequestBody SysUserDTO sysUserDTO){
        return sysUserService.saveUser(sysUserDTO);
    }


    @ApiOperation("删除用户")
    @DeleteMapping("/delete")
    public Result deleteUser(Long userId){
        return sysUserService.deleteUser(userId);
    }


    /**
     * 更新用户信息
     * @param sysUserDTO
     * @param id
     * @returns
     */
    @PostMapping("/update/{id}")
    @ApiOperation("更新用户信息")
    public int updateSysUser(@PathVariable("id") Long  id, @RequestBody SysUserDTO sysUserDTO){
        return sysUserService.updateSysUser(id,sysUserDTO);
    }
    /**
     * 查看用户信息
     * @returns
     */
    @GetMapping("/query/{id}")
    @ApiOperation("查看用户信息")
    public SysUserDTO querySysUser(@PathVariable("id") Long  id){
        return sysUserService.querySysUser(id);
    }



}
